package com.luzhikun.printwriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 向流中添加数据有三种方式
 * <p>
 * write()
 * append()
 * print()
 */

public class PrintWriter extends HttpServlet {
    /*
     * @Author liu-miss
     * @Description  Servlet类doGet方法
     * @Date 13:06 2021/5/1
     * @Param [req, resp]
     * @return void
     **/
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //解决响应将数据传到浏览器上出现的乱码问题
        resp.setContentType("text/html;charset=UTF-8");

        //Web???/printWriter_war_exploded   append 向流中添加数据
        resp.getWriter().append("Web根路径").append(req.getContextPath());

        //Web???/printWriter_war_exploded
        java.io.PrintWriter writer = resp.getWriter();
        writer.println("Web根路径 " + req.getContextPath());

        //  cwwc   dwadawd
        writer.write("cwwc");
        writer.write("dwadawd");

        resp.setCharacterEncoding("UTF-8");

        //设置请求的字符集
        req.setCharacterEncoding("UTF-8");

        //通过请求获取指定参数的值
        String name = req.getParameter("name");

        //é²å¿å¤
        //陈宇璐
        resp.getWriter().println(name);

        //通过响应将这个值传到浏览器界面上
        // 椴佸織鍧�
        //获取标准输出流
        //java.io.PrintWriter writer = resp.getWriter();
        writer.println("鲁志坤");
        writer.println("luzhikun");


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
